package com.sgb.knowledgeshare.viewmodel;

import androidx.lifecycle.ViewModel;
import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.MagessListEntity;
import com.sgb.knowledgeshare.view.activity.ShareSystemMagessActivity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by：冯齐 on 2020/10/19 15:39
 * Description：
 */
public class ShareSystemMagessModel extends ViewModel {
    ShareSystemMagessActivity sharesystemmagessactivity;

    public void setActivity(ShareSystemMagessActivity shareSystemMagessActivity) {
        sharesystemmagessactivity = shareSystemMagessActivity;
    }
    //获取系统消息
    public void getSystemMagessList(int page) {
        Map map = new HashMap();
        map.put("pageNum",page);
        map.put("pageSize",10);
        DialogHelper.showProgressDialog(sharesystemmagessactivity, null, "加载中...", 0, true, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getMsgList(map).enqueue(new ICallBack<BaseEntity<MagessListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<MagessListEntity> data) {
                DialogHelper.dismissProgressDialog();
                if (data.getData() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    sharesystemmagessactivity.setSystemMagessList(data.getData().getRecords());
                }
            }
        });
    }

}
